package netbayServlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import netbay.NetbayUtility;
import netbay.WorkerManager;

/**
 * Servlet implementation class BusinessServlet
 */
@WebServlet("/BusinessServlet")
public class BusinessServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public BusinessServlet() {
		super();
	}
	
	public void init()
	{
		String configPath = getServletContext().getRealPath("/WEB-INF/config.properties");
		System.setProperty("rootPath", getServletContext().getRealPath("/"));
		NetbayUtility.init(configPath);
		
		

	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// Set a cookie for the user, so that the counter does not increate
		// everytime the user press refresh
		// HttpSession session = request.getSession(true);
		// Set the session valid for 5 secs
		// session.setMaxInactiveInterval(5);

		String cmd = request.getParameter("cmd");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		

		if (cmd == null) {

			System.out.println("null cmd");

		}
		else
		{
			
			WorkerManager.assignJob(cmd);

		}

		out.println("This is BusinessServlet. There is nothing for browsing here.");
		

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	}

}
